﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using Telerik.Web.UI;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class PR_SalaryCommand : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        private ICommandBLL cmdBLL = new CommandBLL();
        private IEmployeeTypeBLL empTypeBLL = new EmployeeTypeBLL();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["CMDTYPE"] = Request.QueryString["cmd_type"].ToString();
                bindEmpType();
            }
            
        }

        private void LoadDataGrid()
        {
            Nullable<int> nEmpTypeSeq = ddlEmployeeType.SelectedValue.Length > 0 ? Int32.Parse(ddlEmployeeType.SelectedValue) : (int?)null;
            try
            {
                IList<CommandInfo> infoList = cmdBLL.ListCommand(SystemInfo._CmdEmployee
                    , (int?)null, Convert.ToInt32(Session["CMDTYPE"].ToString()), nEmpTypeSeq);
                RadGrid2.DataSource = infoList;// ListSalaryCommand.Tables[0];
                GridGroupByExpression g = new GridGroupByExpression(RadGrid2.Columns[7]);
                RadGrid2.MasterTableView.GroupByExpressions.Add(g);
                RadGrid2.DataBind();
            }
            catch (Exception ex)
            {

            }
        }
        private void bindEmpType()
        {
            try
            {
                IList<EmployeeTypeInfo> infoList = empTypeBLL.ListEmployeeTypes();
                ddlEmployeeType.DataSource = infoList;
                ddlEmployeeType.DataBind();
            }
            catch
            {

            }
        }

        protected void RadGrid2_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["cmd_seq"]);
                cmdBLL.Delete(SystemInfo._CmdEmployee, seq, ssMng.EmpSeqI);
            }
            if (e.CommandName == "ExpandCollapse")
                return;
            LoadDataGrid();
        }

        protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
        {
            ////cmd_status
            //if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            //{
            //    if (ListSalaryCommand.Tables[0].Rows[e.Item.ItemIndex]["cmd_status"].ToString() == "W")
            //    {
            //        e.Item.Cells[5].Text = ListSalaryCommand.Tables[0].Rows[e.Item.ItemIndex]["cmd_draft_no"].ToString();
            //    }
            //}
        }
        protected void ddlEmployeeType_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            Session["EMPTYPE"] = ddlEmployeeType.SelectedValue;
            LoadDataGrid();
        }
    }
}
